<template>
    <div class="shop-check">
        <div class="shop-check-card">
            <div class="shop-check-head">
                <Row :gutter="5" style="margin-bottom: 10px">
                    <Col span="4">
                        <DatePicker  clearable v-model="searchData.timeStartEnd" style="width: 100%" type="daterange" placeholder="时间筛选"></DatePicker>
                    </Col>
                    <Col span="4">
                        <Input clearable v-model="searchData.shopId" placeholder="店铺Id" type="text"></Input>
                    </Col>
                    <Col span="4">
                        <Input clearable v-model="searchData.shopSn" placeholder="店铺编号" type="text"></Input>
                    </Col>
                    <Col span="4">
                        <Input clearable v-model="searchData.shopName" placeholder="店铺名" type="text"></Input>
                    </Col>
                    <Col span="4">
                        <Input clearable v-model="searchData.shopCompany" placeholder="公司名" type="text"></Input>
                    </Col>
                    <Col span="4">
                        <Input clearable v-model="searchData.shopTel" placeholder="店铺电话" type="text"></Input>
                    </Col>
                </Row>
                <Row :gutter="5">
                    <Col span="4">
                        <Select clearable v-model="searchData.areaId1" placeholder="选择地址(省)" @on-change="getAreaId2">
                            <Option v-for="(value,key) in areaId1List" :value="value.areaid">{{value.areaname}}</Option>
                        </Select>
                    </Col>
                    <Col span="4">
                        <Select clearable v-model="searchData.areaId2" placeholder="选择地址(市)" @on-change="getAreaId3">
                            <Option v-for="(value,key) in areaId2List" :value="value.areaid">{{value.areaname}}</Option>
                        </Select>
                    </Col>
                    <Col span="4">
                        <Select clearable v-model="searchData.areaId3" placeholder="选择地址(县、区)">
                            <Option v-for="(value,key) in areaId3List" :value="value.areaid">{{value.areaname}}</Option>
                        </Select>
                    </Col>
                    <Col span="4">
                        <Select clearable v-model="searchData.goodsCatId1" placeholder="所属行业">
                            <Option v-for="(key,value) in goodsTypeOne" :value="key.catid">{{key.catname}}</Option>
                        </Select>
                    </Col>
                    <Col span="8">
                        <ButtonGroup class="subSearch">
                            <Button :loading="search_loading" @click="searchGetList" type="primary"><Icon type="ios-pulse-strong"></Icon> 筛 选</Button>
                        </ButtonGroup>
                    </Col>
                </Row>
            </div>
            <i-table height="645" stripe :columns="columns" :data="data"></i-table>
            <div style="padding: 15px;">
                <Page @on-page-size-change="changeTiao" @on-change="changePage" :current="index" :total="total" show-elevator show-sizer :placement="'top'" :page-size="page_con" :page-size-opts="[10, 15, 20, 30, 40, 50]"></Page>
            </div>
        </div>

    </div>
</template>

<script>
    export default {
        name: "shop-check",
        data(){
            return{
                columns:[
                    {
                        type: 'expand',
                        width: 30,
                        render: (h, params) => {
                            return h("span",`公司地址: ${params.row.aareaname} ${params.row.bareaname} ${params.row.careaname} ${params.row.shopaddress}`)
                        }
                    },
                    {
                        title: '序号',
                        type: 'index',
                        width: 60,
                        align:"center",
                    },
                    {
                        title: '店铺ID',
                        key: 'shopid',
                        align:"center",
                    },
                    {
                        title: '图标',
                        key: 'shopimg',
                        width:100,
                        align:"center",
                        render:(h,params)=>{
                            if(params.row.shopimg==""){
                                return "暂无"
                            }else{
                                return h("div",{
                                    style:{
                                        cursor: "pointer",
                                    },
                                    on:{
                                        mouseover:(e)=>{
                                            this.$store.commit("setImgData",{
                                                src:e.target.src||e.target.getElementsByTagName("img")[0].src||"",
                                                x:e.x+50+"px",
                                                y:e.y-60+"px",
                                            })
                                        },
                                        mousemove:(e)=>{
                                            this.$store.commit("setImgData",{
                                                src:e.target.src||e.target.getElementsByTagName("img")[0].src||"",
                                                x:e.x+50+"px",
                                                y:e.y-60+"px",
                                            })
                                        },
                                        mouseout:(e)=>{
                                            this.$store.commit("setImgData",{
                                                src:"",
                                                x:"0px",
                                                y:"0px",
                                            })
                                        }
                                    }
                                },[
                                    h("img",
                                        {
                                            attrs:{
                                                src:params.row.shopimg
                                            },
                                            style:{
                                                width:"42px",
                                                height:"42px",
                                                borderRadius:"4px",
                                                margin:"0px auto",
                                                display:"block",
                                            },
                                        })
                                ])
                            }
                        }
                    },
                    {
                        title: '店铺编号',
                        key: 'shopsn',
                        align:"center",
                    },
                    {
                        title: '店铺名',
                        key: 'shopname',
                        align:"center",
                    },
                    {
                        title: '公司名',
                        key: 'shopcompany',
                        align:"center",
                    },
                    {
                        title: '店铺电话',
                        key: 'shoptel',
                        align:"center",
                    },
                    {
                        title: '所属行业',
                        key: 'catname',
                        align:"center",
                    },
                    {
                        title: '添加时间',
                        key: 'createtime',
                        align:"center",
                        render:(h,params)=>{
                            return this.timeFormat(params.row.createtime)
                        }
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width:230,
                        align: 'center',
                        render: (h, params) => {
                            return h('ButtonGroup', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                    },
                                    on: {
                                        click: () => {
                                            this.shopId = params.row.shopid
                                            this.modal1=true
                                        }
                                    }
                                },"审核通过"),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                    },
                                    on: {
                                        click: () => {
                                            this.shopId = params.row.shopid
                                            this.modal2=true
                                        }
                                    }
                                }, '审核驳回')
                            ]);
                        }
                    },
                ],
                data:[],
                total:0,
                index:1,
                page_con:15,
                searchData:{
                    timeStartEnd:[],//两个时间内的赛选
                    shopSn:"",//店铺编号
                    shopName:"",//店铺名
                    shopId:"",//店铺ID
                    shopCompany:"",//公司名
                    shopTel:"",//店铺电话
                    areaId1:"",//省
                    areaId2:"",//市
                    areaId3:"",//县
                    goodsCatId1:"",//所属行业
                    status:"0",//审核状态
                },
                search_loading:false,
                areaId1List:[],//省级
                areaId2List:[],//市级
                areaId3List:[],//县
                goodsTypeOne:[],
                shopId:"",//操作的店铺ID
                modal_loading:false,
                modal1:false,
                modal2:false,
            }
        },
        activated(){
            this.getOrderList()
            this.getAreaId1()
            this.getTypeOneList()
        },
        methods:{
            getOrderList(){
                this.getJsonData("Shops/queryShops",{
                    num:this.page_con,
                    page:this.index,
                    begin:this.searchData.timeStartEnd[0]?this.searchData.timeStartEnd[0]/1000:"",
                    last:this.searchData.timeStartEnd[1]?this.searchData.timeStartEnd[1]/1000:"",
                    shopId:this.searchData.shopId,
                    shopSn:this.searchData.shopSn,
                    shopName:this.searchData.shopName,
                    shopCompany:this.searchData.shopCompany,
                    shopTel:this.searchData.shopTel,
                    areaId1:this.searchData.areaId1,
                    areaId2:this.searchData.areaId2,
                    areaId3:this.searchData.areaId3,
                    goodsCatId1:this.searchData.goodsCatId1,
                    status:this.searchData.status,
                },true)
                    .then((res)=>{
                        this.data=res.data
                        this.total=parseInt(res.count)
                        this.search_loading=false
                    })
                    .catch((res)=>{
                        this.search_loading=false
                    })
            },
            //获取商品一级分类
            getTypeOneList(){
                this.getJsonData("Cat/getOneCat")
                    .then((res) => {
                        this.goodsTypeOne=res.data
                    })
            },
            //获取省
            getAreaId1(){
                this.getJsonData("Areas/getAreas",{parentId:""})
                    .then((res)=>{
                        this.areaId1List = res.data
                    })
            },
            //获取市
            getAreaId2(){
                if(this.searchData.areaId1!==""){
                    this.getJsonData("Areas/getAreas",{parentId:this.searchData.areaId1})
                        .then((res)=>{
                            this.areaId2List = res.data
                        })
                }else{
                    this.areaId2List = []
                    this.areaId3List = []
                }
            },
            //获取县
            getAreaId3(){
                if(this.searchData.areaId2!==""){
                    this.getJsonData("Areas/getAreas",{parentId:this.searchData.areaId2})
                        .then((res)=>{
                            this.areaId3List = res.data
                        })
                }else{
                    this.areaId3List = []
                }
            },
            changePage(n){
                this.index=n
                this.getOrderList()
            },
            changeTiao(num){
                this.page_con=num
                this.index=1
                this.getOrderList()
            },
            searchGetList(){
                this.search_loading=true
                this.index=1
                this.getOrderList()
            },
            //删除店铺
            delShop(){
                this.modal_loading = true;
                this.getJsonData("Shops/checkShop",{shopId:this.shopId,type:1},true)
                    .then((res)=>{
                        this.getOrderList()
                        this.modal_loading = false;
                        this.modal1 = false;
                        this.$Message.success('审核已通过');
                    }).catch((res)=>{
                    this.modal_loading = false;
                    this.modal1 = false;
                })
            },
            //重置密码
            resetPwd(){
                this.modal_loading = true;
                this.getJsonData("Shops/checkShop",{shopId:this.shopId,type:2},true)
                    .then((res)=>{
                        this.getOrderList()
                        this.modal_loading = false;
                        this.modal2 = false;
                        this.$Message.success('审核已驳回');
                    }).catch((res)=>{
                    this.modal_loading = false;
                    this.modal2 = false;
                })
            }
        },
    }
</script>

<style lang="less">
    @import "shop-check";
</style>